<!--Copyright (C) 2018 Riedel Communications GmbH & Co. KG

  Modifications Copyright 2018 British Broadcasting Corporation

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>NMOS Tests</title>
    <link rel="stylesheet" href="static/css/bootstrap.min.css">
    <link rel="stylesheet" href="static/css/style.css?nocache-{{ cachebuster }}">
    <script src="static/js/result_script.js?nocache-{{ cachebuster }}"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <div style="display: none" id="json-results">{{ json }}</div>
    <span class="backlink">
        <a href="#" id="download" target="_blank">Download JSON</a> - <a href="../">More Options</a>
    </span>
    <h1>NMOS Test</h1>
    <div class="text text_result">
        <h5>Result for test suite <b>{{ test }}</b>{% if urls|length > 0 %} on:{% endif %}
            {% for url in urls %}
                <b><a href={{ url }}>{{ url }}</a></b>{% if loop.index != loop.length %},{% endif %}
            {% endfor %}
        </h5>
    </div>
    <div class="text text_result">
        <form action="" method="POST" onsubmit="disableRunbtn(); return true;">
            <div style="display: none;">
                {{ form.test }}
                {{ form.hidden_tests }}
                {{ form.hidden_specs }}
                {{ form.hidden_options }}
                {% for endpoint in form.endpoints %}
                    {{ endpoint.host }}
                    {{ endpoint.port }}
                    {{ endpoint.version }}
                    {{ endpoint.selector }}
                    {{ endpoint.urlpath }}
                {% endfor %}
                <input type="checkbox" unchecked id="auto_all" name="test_selection" value="auto"/>
            </div>
            <br/>
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th colspan="6">
                            <div style="position: absolute" onclick="document.getElementById('failed_all').click();">
                                <input type="checkbox" id="failed_all" unchecked onclick="event.stopPropagation(); changeTestSelection(this);"/>
                                <label id="failed_all_label" style="opacity: 1;"> Failed Tests</label>
                            </div>
                            <input  type="submit" id="runbtn" value="Run"/>
                        </th>
                    </tr>
                    <tr>
                        <th>Test</th>
                        <th>Pass</th>
                        <th>Description</th>
                        <th>Reason</th>
                        <th>Completion Time</th>
                        <th>Time Elapsed</th>
                    </tr>
                </thead>
                <tbody>
                    {% for curr_result in result %}
                        {% set curr_auto = curr_result[0].startswith("auto_") %}
                        {% set curr_test = curr_result[0].startswith("test_") or curr_auto %}
                        {% set curr_fail = curr_result[2]=='bg-danger' %}
                        <tr {% if curr_test %} onclick="document.getElementById('{{ curr_result[0] }}').click();" {% endif %}>
                            <td style="white-space: nowrap;">
                                {% if curr_test %}
                                    <input type="checkbox"
                                        {% if not curr_auto %}
                                            name="test_selection" value="{{ curr_result[0] }}"
                                        {% endif %}
                                        class="{% if curr_auto %}auto{% endif %} {% if curr_fail %}failed{% endif %}"
                                        id="{{ curr_result[0] }}" onclick="event.stopPropagation(); changeTestSelection(this);"
                                    />
                                    <label>
                                        {{ curr_result[0] }}
                                    </label>
                                {% else %}
                                    {{ curr_result[0] }}
                                {% endif %}
                            </td>
                            <td style="white-space: nowrap;" class="{{ curr_result[2] }} pass_state">{{ curr_result[1] }}</td>
                            <td style="word-break: break-word;">{{ curr_result[3] }}</td>
                            <td>
                                {{ curr_result[4] }}
                                {% if curr_result[5] %}
                                    <a href="{{ curr_result[5] }}" target="_blank">More Information</a>
                                {% endif %}
                            </td>
                            <td>{{ curr_result[6] }}</td>
                            <td>{{ curr_result[7] }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
            <div class="footnote">
                {{ config }}
            </div>
        </form>
    </div>
</body>
</html>
